#include"CCThread.h"

int detach_thread_creat(pthread_t* thread,void* strat_routine,void* arg){
    pthread_attr_t attr; //线程属性
    pthread_t thread_t;

    int ret = 0;
    if(thread==NULL){
        thread = &thread_t;
    }

    //初始化属性
    if(pthread_attr_init(&attr)){
        printf("pthread_attr_init failed");
        return -1;
    }

    if(pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED)){ 
        printf("pthread_attr_setdetachstate failed");
        pthread_attr_destroy(&attr);
        return -1;
    }

    ret = pthread_create(thread,&attr,(void*(*)(void*))strat_routine,arg);
    if(ret<0){
        printf("pthread_create failed");
        pthread_attr_destroy(&attr);
        return -1;
    }

    ret = pthread_detach(thread_t);
    return ret;

}